﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.Web;
using System.Web.UI.WebControls;
using JumbotCms.Common;
namespace JumbotCms.WebFile.Admin
{
    public partial class _user_edit : JumbotCms.API.AdminCenter
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Admin_Load("0000", "html");
            id = Str2Str(q("id"));
            Jumbot.DataOper.WebFormHandler wh = new Jumbot.DataOper.WebFormHandler(doh, "jcms_normal_user", btnSave);
            wh.AddBind(txtUserName, "UserName", true);
            wh.AddBind(txtMax, "Integral", true);
            this.txtUserName.ReadOnly = true;
            wh.ConditionExpress = "id=" + id;
            wh.Mode = Jumbot.DataOper.OperationType.Modify;
            wh.validator = chkForm;
            wh.ModifyOk += new EventHandler(save_ok);
        }
        protected void bind_ok(object sender, EventArgs e)
        {
        }
        protected bool chkForm()
        {
            if (!CheckFormUrl())
                return false;
            if (!Page.IsValid)
                return false;
            return true;
        }
        protected void save_ok(object sender, EventArgs e)
        {
            string _uName = this.txtUserName.Text;
            JumbotCms.DataObject.User _User = new JumbotCms.DataObject.User();
            if (this.txtUserPass.Text.Length > 0)
            {
                _User.ChangePsd(id, GetHash32(this.txtUserPass.Text), doh);
                SaveAdminLog("修改了ID为" + id + "的用户的密码为:" + this.txtUserPass.Text);
            }
            if (this.txtPoints.Text != "0")
            {
                _User.AddPoints(id, Str2Int(this.txtPoints.Text), doh);
                SaveAdminLog("给[" + _uName + "]充点数:" + this.txtPoints.Text);
                SaveUserLog(id, AdminName + "给你充了" + this.txtPoints.Text + "点数", 4);
            }
            if (this.ddlVIPYears.SelectedValue != "0")
            {
                _User.AddVIPYears(id, Str2Int(this.ddlVIPYears.SelectedValue), doh);
                SaveAdminLog("给[" + _uName + "]包了" + this.ddlVIPYears.SelectedValue + "年VIP服务");
                SaveUserLog(id, AdminName + "给你包了" + this.ddlVIPYears.SelectedValue + "年VIP服务", 5);

            }
            if (this.txtIntegral.Text != "0")
            {
                _User.SubstractIntegral(id, Str2Int(this.txtIntegral.Text), doh);
                SaveAdminLog("给[" + _uName + "]扣积分:" + this.txtIntegral.Text);
                SaveUserLog(id, AdminName + "给你扣除" + this.txtIntegral.Text + "积分", 4);
            }
            FinalMessage("成功保存", site.Dir + "admin/close.htm", 0);
        }
    }
}
